package com.sc.nft.dao;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.PackageRule;
import com.sc.nft.mapper.PackageRuleMapper;
import  com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 套餐主表(sc_package_rule)数据DAO
 *
 * @author zxy
 * @since 2023-10-14 02:01:22
 * @description 汇付相关
 */
@Slf4j
@Repository
public class PackageRuleDao extends ServiceImpl<PackageRuleMapper, PackageRule> {


    public List<PackageRule> simpleList() {
        LambdaQueryWrapper<PackageRule> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(PackageRule::getId,PackageRule::getPackageName);
        return list(wrapper);
    }

    public PackageRule getByCollectionId(Long collectionId) {
        return lambdaQuery().eq(PackageRule::getCollectionId,collectionId).one();
    }

    public PackageRule getOpenByCollectionId(Long collectionId) {
        return lambdaQuery().eq(PackageRule::getStatus,true).eq(PackageRule::getCollectionId,collectionId).one();
    }
    public Page<PackageRule> getAdminPage(Page page, String packageName, Long collectionId, Date startTime, Date endTime) {
        return lambdaQuery()
                .like(StrUtil.isNotBlank(packageName),PackageRule::getPackageName,packageName)
                .eq(collectionId!=null,PackageRule::getCollectionId,collectionId)
                .le(ObjectUtil.isNotNull(startTime),PackageRule::getCreateTime,startTime)
                .ge(ObjectUtil.isNotNull(endTime),PackageRule::getCreateTime,endTime)
                .page(page);
    }
}